package com.dofast.bt.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dofast.bt.R;
import com.dofast.bt.base.BaseApplication;
import com.dofast.bt.bean.GoodsBean;
import com.dofast.bt.util.Helper;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * username:Created by hsj on 2016/12/8 0008.
 * class：
 * 类描述：茶列表
 */

public class TeaAdapter extends BaseAdapter {
    private List<GoodsBean> list = new ArrayList<GoodsBean>();

    public TeaAdapter(List<GoodsBean> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (null == convertView) {
            convertView = LayoutInflater.from(BaseApplication.getInstance().getApplicationContext()).inflate(R.layout.item_tea_info, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Glide.with(BaseApplication.getInstance().getApplicationContext()).load(list.get(position).getImg_head()).placeholder(R.mipmap.tea).into(holder.ivPhoto);

        if (!TextUtils.isEmpty(list.get(position).getName())) {
            holder.tvName.setText(list.get(position).getName());
        } else {
            holder.tvName.setText("");
        }
        holder.txtPrice.setText("¥ " + list.get(position).getPrice());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.iv_photo)
        ImageView ivPhoto;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.txt_price_s)
        TextView txtPriceS;
        @BindView(R.id.txt_price)
        TextView txtPrice;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
